import random
from datetime import datetime, timedelta
from time import sleep

from dao.mysqlhelper import MySQLHelper


def creat_sqls(start_date, num_days):
    sql_list = []
    start_date = datetime.strptime(start_date, '%Y-%m-%d')
    for i in range(num_days):
        current_date = start_date - timedelta(days=i)
        date_str = current_date.strftime('%Y-%m-%d')
        formatted_number1= [f"{random.randint(45, 59):02}" for _ in range(4)]
        formatted_number2= [f"{random.randint(10, 59):02}" for _ in range(4)]

        # 逐条生成 SQL 数据
        sql_list.append(f"""INSERT INTO `tw-tunnel`.tunnel_peak_trend (peak_trend_id, tunnel_direction, hour_period_begin, hour_period_end, peak_type, count_date, del_flag, create_time, update_time, tenant_id) VALUES(uuid(), 2, '{date_str} 17:{formatted_number1[0]}:{formatted_number2[0]}', '{date_str} 18:{formatted_number1[1]}:{formatted_number2[1]}', 1, '{date_str} 02:00:00', '0', '{date_str} 02:00:00', '{date_str} 02:00:00', 'T1000')""")
        # sql_list.append(f"""INSERT INTO `tw-tunnel`.tunnel_peak_trend (peak_trend_id, tunnel_direction, hour_period_begin, hour_period_end, peak_type, count_date, del_flag, create_time, update_time, tenant_id) VALUES(uuid(), 1, '{date_str} 17:{formatted_number[4]}:{formatted_number[5]}', '{date_str} 18:{formatted_number[6]}:{formatted_number[7]}', 1, '{date_str} 02:00:00', '0', '{date_str} 02:00:00', '{date_str} 02:00:00', 'T1000')""")
        sql_list.append(f"""INSERT INTO `tw-tunnel`.tunnel_peak_trend (peak_trend_id, tunnel_direction, hour_period_begin, hour_period_end, peak_type, count_date, del_flag, create_time, update_time, tenant_id) VALUES(uuid(), 1, '{date_str} 07:{formatted_number1[2]}:{formatted_number2[2]}', '{date_str} 08:{formatted_number1[3]}:{formatted_number2[3]}', 0, '{date_str} 02:00:00', '0', '{date_str} 02:00:00', '{date_str} 02:00:00', 'T1000')""")
        # sql_list.append(f"""INSERT INTO `tw-tunnel`.tunnel_peak_trend (peak_trend_id, tunnel_direction, hour_period_begin, hour_period_end, peak_type, count_date, del_flag, create_time, update_time, tenant_id) VALUES(uuid(), 2, '{date_str} 07:{formatted_number[12]}:{formatted_number[13]}', '{date_str} 08:{formatted_number[14]}:{formatted_number[15]}', 0, '{date_str} 02:00:00', '0', '{date_str} 02:00:00', '{date_str} 02:00:00', 'T1000')""")
    return sql_list

# 隧道近7日早晚高峰数据构造，入参为时间，和天数     只造这个时间段  南线1  7：50-8：40    北向2  17：40-18：40
mysql=MySQLHelper()
sql_list = creat_sqls("2024-12-03", 7)
for sql in sql_list:
    mysql.dml(sql)
    sleep(0.1)

